package com.arg.friday.controller;

import com.arg.friday.dao.MockDatabase;
import com.arg.friday.entity.Dog;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Random;

@RestController
public class Restful {

    @Resource
    private MockDatabase mockDatabase;
    @GetMapping(value = "/dogs")
    public List<Dog> getAll(){
       return mockDatabase.getDogs();
    }
    @Resource
    private Random random;
    @PutMapping(value = "/dog")
    public Dog saveOne(@RequestBody Dog dog){
        dog.setId((random.nextInt(8999)+1000)+"");
        mockDatabase.getDogs().add(dog);
        return dog;
    }
    @GetMapping(value = "/dog/{id}")
    public Dog findOne(@PathVariable String id,@RequestHeader String token){
        System.out.println(token);
       return mockDatabase.getDogs()
                .stream()
                .filter(dog -> dog.getId().equals(id))
                .findFirst()
                .orElse(null);
    }


}
